home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip0493.zip / TOUCH.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  2KB  |  64 lines

  1. /*----------------------------------------------------------------------*
  2. * Program:     touch                                                    *
  3. * Programmer:  Ray L. McVay                                             *
  4. * Started:     8 Aug 91                                                 *
  5. * Updated:     13 Feb 93 Thad Smith                                     *
  6. * Updated:     15 Feb 93 Bob Stout                                      *
  7. *-----------------------------------------------------------------------*
  8. * Simple touch program to test BC time stamping function.               *
  9. * Public Domain                                                         *
  10. *----------------------------------------------------------------------*/
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <time.h>
  15. #ifdef __TURBOC__
  16.  #include <dos.h>
  17.  #include <io.h>
  18. #else
  19.  #include "ftime.h"                 /* Borland work-alike in SNIPPETS   */
  20. #endif
  21.  
  22. void usage(void);
  23.  
  24. main(int argc, char **argv)
  25. {
  26.       time_t    tnow;
  27.       struct tm tmnow;
  28.       struct ftime ft;
  29.       FILE *f;
  30.  
  31.       if (argc < 2)
  32.             usage();
  33.  
  34.       tnow  = time(NULL);
  35.       tmnow = *localtime(&tnow);
  36.  
  37.       ft.ft_year  = tmnow.tm_year - 80;
  38.       ft.ft_month = tmnow.tm_mon + 1;
  39.       ft.ft_day   = tmnow.tm_mday;
  40.       ft.ft_hour  = tmnow.tm_hour;
  41.       ft.ft_min   = tmnow.tm_min;
  42.       ft.ft_tsec  = tmnow.tm_sec/2;
  43.  
  44.       if ((f = fopen(argv[1], "r+b")) != NULL)
  45.             setftime(fileno(f), &ft);
  46.       else if ((f = fopen(argv[1], "w")) != NULL)
  47.             setftime(fileno(f), &ft);
  48.       else  perror("Can't open file");
  49.  
  50.       if (f)
  51.             fclose(f);
  52.  
  53.       return EXIT_SUCCESS;
  54. }
  55.  
  56. void usage(void)
  57. {
  58.       puts("Usage: TOUCH filename\n");
  59.       puts("  The timestamp of filename will be set to the current time.");
  60.       puts("  A zero-length file will be created if the file doesn't exist.");
  61.       exit(EXIT_FAILURE);
  62. }
  63.  
  64.